#!/bin/bash
#
# tailsecured          Start/Stop the tailsecured daemon.
#
# chkconfig: 2345 90 60
# description:tailsecured transfer /var/log/secure data to a remote syslog
# processname: tailsecured
# config: /etc/sysconfig/tailsecured
# pidfile: /var/run/tailsecured.pid

# Source function library.
. /etc/init.d/functions

# Source config file
if [ -f /etc/sysconfig/tailsecured ];then
        . /etc/sysconfig/tailsecured
fi

PIDPATH=/var/run
SRVNAME=tailsecured
execprog="/usr/bin/php /usr/local/tailsecured/tailsecured.php $SERVER $TAILFILE $CHECKTIMEOUT"
lockfile=/var/lock/subsys/tailsecured

start() {
	RETVAL=1
	echo -n "Starting $SRVNAME : "
        if [ ! -f $PIDSPATH/$SRVNAME.pid ]; then
		$execprog &
		RETVAL=$?
		PROCPID=$!
		echo "$PROCPID" >> $PIDSPATH/$SRVNAME.pid
    	else
		echo -n " Already Running "
	fi
        
	if [ $RETVAL -eq 0 ]; then
		touch $lockfile
		success
	else
		failure
	fi
	echo 
	return $RETVAL
}
	
stop() {
        echo -n $"Shutting down $SRVNAME: "
	killproc -p "$PIDSPATH/$SRVNAME.pid" $SRVNAME
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f $lockfile
	return $RETVAL
}

# See how we were called.
case "$1" in
  start)
	start
        ;;
  stop)
	stop
        ;;
  status)
	status -p "$PIDSPATH/$SRVNAME.pid" $SRVNAME
	RETVAL=$?
	;;
  restart|reload)
	stop
	start
	RETVAL=$?
	;;
  *)
        echo $"Usage: $0 {start|stop|restart|status}"
        RETVAL=3
esac

exit $RETVAL
